<template>
	<view>
		<!-- 自定义导航栏 -->
		<view class="navBarBox">
			<!-- 状态栏占位 -->
			<view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
			<!-- 真正的导航栏内容 -->
			<view class="navBar">
				<view class="goback">
					<view @click="goBack" class="goicon" style="background:url(../../static/goback.png);background-size:contain;background-repeat: no-repeat;">
					</view>
				</view>
				<view class="title">邀约设置</view>
				<view class="right">
				</view>
			</view>
		</view>
		<!-- 页面内容 -->
		<view class="content">
			<view class="contlist"  >
				
				<view class="contlistcont" v-for="(item,index) in getTime" :key="item.value" >
					<view class="listdaybox">
						<view class="listdaytexbg">
							<text>{{item.appointWeek | weekChange}}</text>
						</view>
					</view>
					<view class="listtimebox">
						<view class="listtime">
							{{item.teachingTime | weekChanges}}
						</view>
					</view>
				</view>
				
			</view>
			
			<view class="contlist contplace">
				<view class="contlistcont">
					<view class="listdaybox">
						<view class="listdaytexbg">
							<text>场地</text>
						</view>
					</view>
					<view class="listtimebox">
						<view>
							<view class="uni-list-cell">

								<view class="uni-list-cell-db">
									<picker @change="bindPickerChange" :value="index" :range-key="'placeName'" :range="getPlaces">
										<view class="uni-input">{{getPlaces[index].placeName}}</view>
									</picker>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部提交按钮 -->
		<button class="setclssbt" @click="setPlace">确认提交</button>
	</view>

	</view>
</template>

<script>
	export default {
		data() {

			return {
				getdata:[],//课程全部信息
				getTime:[],//课程时间
				schoolId:0,//当前学校的id
				getPlaces:[],//当前学校的场地
				placeId:1,//当前场地的id
				applyCourseId:4,//当前课程的
				getplace:['足球场','篮球场','阶梯教室'],
				title: 'picker',
				// array: ['中国', '美国', '巴西', '日本'],
				index: 0,

				// 状态栏高度
				statusBarHeight: 0,
				// 导航栏高度
				navBarHeight: 82 + 11,
			};
		},
		filters:{
			weekChange:function(value){
				// console.log(value)
				let text = "周";
				let numAray = [
					{num:1,text:"一",time:"9:00-10:00"},
					{num:2,text:"二",time:"11:00-12:00"},
					{num:3,text:"三",time:"14:00-15:00"},
					{num:4,text:"四",time:"16:00-17:00"},
					{num:5,text:"五",time:"17:00-18:00"},
					{num:6,text:"六",time:"18:00-19:00"},
					{num:7,text:"日"}
				];
				
				numAray.forEach(item => {
					if(item.num == value){
						text = text + item.text;
					}
				})
				return text
			},
			
			weekChanges:function(value){
				
				let time=''
				let numArays = [
					{num:1,time:"9:00-10:00"},
					{num:2,time:"11:00-12:00"},
					{num:3,time:"14:00-15:00"},
					{num:4,time:"16:00-17:00"},
					{num:5,time:"17:00-18:00"},
					{num:6,time:"18:00-19:00"},
					
				];
				
				numArays.forEach(item => {
					if(item.num == value){
						time=item.time
					}
					
				})
				return time
			}
		},
		props: {},
		//第一次加载时调用
		created() {
			//获取手机状态栏高度
			this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
		},
		// onLoad:function(option){
		// 	 console.log(option.query)
		// 	  const eventChannel = this.getOpenerEventChannel()
		// 	  eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
		// 	  eventChannel.emit('someEvent', {data: 'test'});
		// 	  // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
		// 	  eventChannel.on('acceptDataFromOpenerPage', function(data) {
				 
		// 		 this.getdata=data.data
		// 		 this.getTime=this.getdata.time	
		// 		console.log(this.getdata,"接到的数据")
		// 		console.log(this.getTime,'时间')
		// 	  })
		// },
		
		onLoad:function (option) {
			const item = JSON.parse(decodeURIComponent(option.item));
			this.getTime=item.time;//获取课程的时间
			this.schoolId= item.inviteSchoolId;//获取机构/学校id
			this.applyCourseId=item.id;
			this.getPalce()
			
		},
		computed: {
		},
		onShow:function() {
			console.log( this.getTime,'这是取到的值')
			console.log( typeof(this.schoolId) ,'当前学校的id')
			console.log( typeof(this.applyCourseId) ,'当前课程的id')
			
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e)
				let a=e.target.value
				this.placeId=this.getPlaces[a].id
				// console.log(this.placeId,'选择的地址下拉的id')
			},
			
			goBack() {// 返回上一页
				// 此处是写返回页面的方法、
				uni.navigateBack({
					delta: 1 //返回只上一级页面
				});
			},
			getPalce:function(){//获取学校的场地
				this.$myRequest({
					url:'/admin/course/findPlace/'+this.schoolId,
					method:'get',
					
					success: (res) => {
						 this.getPlaces = res.data.data
						console.log(this.getPlaces, 'getPalce')
					
					},
					fail: (err) => {
						console.log(err)
						console.log('获取数据中')
					
					}
				})
			},
			setPlace(){
				this.$myRequest({
					
					url:'/admin/course/enter',
					method:'get',
					data:{
						applyCourseId:this.applyCourseId,
						placeId:this.placeId
					},
					
					
					success: (res) => {
						console.log('设置成功')
					
						uni.navigateTo({
							url:'./courseInviteList'
						})
					
					},
					fail: (err) => {
						console.log(err)
						console.log('获取数据中')
					
					}
				})
			}
			
			
		}
		
	}
</script>

<style>
	.navBarBox {}

	.navBarBox .statusBar {}

	.navBarBox .navBar {
		padding: 3rpx 50rpx;
		padding-bottom: 8rpx;
		display: flex;
		justify-content: space-between;

		line-height: 93rpx;
		font-size: 40rpx;
	}

	.goback {
		flex: 1;
		height: 100%;
	}

	.goicon {
		width: 30rpx;
		height: 30rpx;
		background-color: #00BEA9;
		margin-top: 30rpx;
	}

	.title {
		flex: 1;
		height: 100%;

	}

	.right {
		flex: 1;
	}

	/* 中间可盒子 */
	.content {
		width: 100%;
		height: 100%;
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
	}

	.contlist {
		width: 100%;
		
		background-color: #FFFFFF;
		border-bottom: 1rpx #e1e1e1 solid;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		align-items: center;

	}

	.contlist:first-child {
		margin-top: 20rpx;
		margin-bottom: 10rpx;
	}

	.contlistcont {
		width: 690rpx;
		height: 120rpx;
		display: flex;
		flex-wrap: wrap;
		align-content: space-between;

	}

	.listdaybox {
		width: 100%;
		height: 50rpx;


	}

	.listdaytexbg {
		width: 100rpx;
		height: 25rpx;
		margin-top: 10rpx;
		background-color: #a2f8ee;
		line-height: 40rpx;
		align-items: center;
		display: flex;
		justify-content: center;
		font-size: 38rpx;
	}

	.listtimebox {
		width: 100%;
		height: 60rpx;

		display: flex;
		justify-content: space-between;
	}

	.listtime {
		width: 48%;
		height: 100%;
		background-color: #a2f8ee;
		border-radius: 10rpx;
		text-align: center;
		font-size: 26rpx;
		line-height: 60rpx;
	}

	.setclssbt {
		width: 225rpx;
		height: 70rpx;
		border-radius: 10rpx;
		font-size: 26rpx;
		text-align: center;
		line-height: 70rpx;
		margin-top: 60rpx;
		color: #FFFFFF;
		border: none;
		background-color: #2db3fe;
		box-shadow: 5rpx 5rpx 10rpx 2rpx #2db3fe;
	}
</style>
